package com.xk857.forum.controller.pub;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xk857.config.AuthUtil;
import com.xk857.entities.Forum;
import com.xk857.entities.SysUser;
import com.xk857.forum.service.IForumService;
import com.xk857.util.base.BaseRequest;
import com.xk857.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.*;

/**
 * 星空小屋-论坛话题表 前端控制器
 *
 * @author CV大魔王
 * @since 2021-02-23
 */
@Api(value = "论坛话题接口(公开)", tags = "论坛话题接口(公开)")
@RestController
@RequestMapping("/pub/forum")
public class PubForumController {

    @Autowired
    private IForumService forumService;


    @ApiOperation("分页查询热门话题列表接口")
    @PostMapping("/hot")
    public IPage<Forum> findHostList(@RequestBody BaseRequest<Forum> req) {
        return forumService.findHotList(req);
    }


    @ApiOperation("分页查询最新话题列表")
    @PostMapping("/new")
    public IPage<Forum> findNewList(@RequestBody BaseRequest<Forum> req) {
        return forumService.findNewList(req);
    }


    @ApiOperation("分页查询待回复话题列表")
    @PostMapping("/wait")
    public IPage<Forum> findWaitList(@RequestBody BaseRequest<Forum> req) {
        return forumService.findWaitList(req);
    }

    @ApiImplicitParam(name = "labelId", value = "标签ID", required = true)
    @ApiOperation("根据标签ID分页查询话题列表接口")
    @PostMapping("/list/{labelId}")
    public IPage<Forum> findListByLabelId(@RequestBody BaseRequest<Forum> req, @PathVariable("labelId") String labelId) {
        return forumService.findListByLabelId(req, labelId);
    }

    @ApiOperation("查询话题详情接口")
    @ApiImplicitParam(name = "id", value = "话题ID", required = true)
    @GetMapping("/{id}")
    public Forum view(@PathVariable("id") String id) {
        return forumService.findById(id);
    }


    @ApiImplicitParam(name = "id", value = "话题ID", required = true)
    @ApiOperation("更新浏览次数")
    @PutMapping("/viewCount/{id}")
    public Result updateViewCount(@PathVariable("id") String id) {
        return forumService.updateViewCount(id);
    }

}
